package com.dnd.dao.impl;

import java.util.List;

import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.dao.DataAccessException;
import org.springframework.orm.hibernate3.HibernateTemplate;
import org.springframework.stereotype.Repository;

import com.dnd.dao.UserDao;
import com.dnd.model.User;

@Repository("userDao")
public class UserDaoImpl implements UserDao {

	private SessionFactory sessionFactory;
    private HibernateTemplate hibernateTemplate;

    @Autowired
    public void setSessionFactory(SessionFactory sessionFactory) {
        this.sessionFactory = sessionFactory;
        this.hibernateTemplate = new HibernateTemplate(sessionFactory);
    }
    
	@Override
	public User getUserByID(Long id) throws DataAccessException {
		return null;
	}

	@Override
	public void save(User user) throws DataAccessException {
		hibernateTemplate.saveOrUpdate(user);
	}

	@Override
	public List<User> list() throws DataAccessException {
		return this.hibernateTemplate.find("from User");
	}

}
